<template>
  <div class="container-fluid px-0 flex-shrink-0">
    <GlobalHeader :user="currentUser"></GlobalHeader>
    <Loader v-if="isLoading"
            text="拼命加载"></Loader>

    <router-view></router-view>

    <footer class="text-center py-4 text-secondary bg-light mt-6">
      <small>
        <ul class="list-inline mb-0">
          <li class="list-inline-item">@ 2022 Zheye-Column</li>
          <li class="list-inline-item"></li>
          <li class="list-inline-item">Welcome</li>
          <li class="list-inline-item">Aurora</li>
        </ul>
      </small>
    </footer>

  </div>

</template>

<script lang="ts">
import { defineComponent, computed, watch } from 'vue'
import { useStore } from 'vuex'
import { GlobalDataProps } from './store'
import 'bootstrap/dist/css/bootstrap.min.css'
import GlobalHeader from './components/GlobalHeader.vue'
import Loader from './components/Loader.vue'
import createMessage from './components/createMessage'


export default defineComponent({
  name: 'App',
  components: {
    GlobalHeader,
    Loader,
  },
  setup() {
    const store = useStore<GlobalDataProps>()
    const currentUser = computed(() => store.state.user)
    const isLoading = computed(() => store.state.isLoading)
    const error = computed(() => store.state.error)
    console.log(currentUser);


    // 监视status的变化
    watch(() => error.value.status, () => {
      const { status, message } = error.value
      if (status && message) {
        createMessage(message, 'error', 2000)
      }
    })

    return {
      isLoading,
      currentUser,
      error
    }
  }

}

)
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

}

a {
  text-decoration: none;
  color: black
}
</style>
